<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			*{
				padding: 0%;
				margin: 0%;
			}
			#box{
				background-color: red;
				width: 200px;
				height: 200px;
				position: relative;
				left: -200px;
			}
			#box span {
				width: 40px;
				height: 60px;
				position: absolute;
				right: -40px;
				top: 50%;
				margin-top: -30px;
				line-height: 60px;
				text-align: center;
				background-color: black;
				color: #fff;
				
			}
		</style>
	</head>
	<body>
		<div id="box">
			<span>拉开</span>
		</div>
	</body>
	<script>
		let box = document.getElementById("box");
		let timer = null;
		let speed = 0;
		box.onmouseover = function() {
			startAnimation(this,0)
		}
		box.onmouseout = function() {
			startAnimation(this,-200)
		}
		function startAnimation(obj,end) {
			clearInterval(timer);
			speed = end > obj.offsetLeft ? 5 : -5;
			timer = setInterval(function() {
				if(obj.offsetLeft === end) {
					clearInterval(timer);
				}else{
					obj.style.left = obj.offsetLeft + speed + "px";
				}
			},30);
		}
	</script>
</html>